<?php
class SocializrUtils {
  public static function getBaseUri() {
    if(class_exists('Socializr') and method_exists('Socializr', 'getOntoWikiBaseUri')) {
      return Socializr::getInstance()->getOntoWikiBaseUri();
    }
    if(class_exists('sfContext')) {
      return
        substr(sfContext::getInstance()->getRequest()->getUri(), 0, strpos(sfContext::getInstance()->getRequest()->getUri(),
        sfContext::getInstance()->getRequest()->getRelativeUrlRoot()) + strlen(sfContext::getInstance()->getRequest()->getRelativeUrlRoot()));
    }
  }
  
  public static function getConnectorUrl()
  {
    if(class_exists('Socializr') and method_exists('Socializr', 'getOntoWikiBaseUri')) {    
      return self::getBaseUri()."/model/connect/network/facebook/account/".SocializrUtils::id2param($account["accountId"]);
    } elseif(class_exists('sfContext')) {
      return sfContext::getInstance()->getRequest()->getUri();
    }
  }
  
  /**
   * turn id into url parameter
   */
  public static function id2param($id) {
    $param = str_replace('+', '++', $id);
    $param = str_replace('/', '+_', $param);
    
    return $param;
  }

  /**
   * turn url parameter into id
   */
  public static function param2id($param) {
    $id = str_replace('++', '+', $param);
    $id = str_replace('+_', '/', $id);
    
    return $id;
  }
}
?>